﻿using Common.Library.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Clinent.Main.View.IconFontBrowse
{
    /// <summary>
    /// UcIconFontBrowse.xaml 的交互逻辑
    /// </summary>
    public partial class UcIconFontBrowse 
    {
        /// <summary>
        /// IconFont的路径
        /// </summary>
        private readonly string iconFontUrl = FileHelper.GetCurrentAppPath() + @"Resources\IconFont\Basic\demo_index.html";

        public UcIconFontBrowse()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 屏蔽脚本错误弹窗
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void wbMain_Navigated(object sender, NavigationEventArgs e)
        {
            var fiComWebBrowser = typeof(WebBrowser).GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic);
            if (fiComWebBrowser == null)
                return;

            object objComWebBrowser = fiComWebBrowser.GetValue(wbMain);
            if (objComWebBrowser == null)
                return;

            objComWebBrowser.GetType().InvokeMember("Silent", System.Reflection.BindingFlags.SetProperty, null, objComWebBrowser, new object[] { true });
        }

        private void Border_Loaded(object sender, RoutedEventArgs e)
        {
            Uri uri = new Uri(iconFontUrl, UriKind.RelativeOrAbsolute);
            wbMain.Navigate(uri);
        }

        /// <summary>
        /// 在默认浏览器中打开
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOpenToDefaultWebBrower_Click(object sender, RoutedEventArgs e)
        {
            Uri uri = new Uri(iconFontUrl, UriKind.RelativeOrAbsolute);
            System.Diagnostics.Process.Start(uri.AbsoluteUri);
        }

        private void btnRefresh_Click(object sender, RoutedEventArgs e)
        {
            wbMain.Refresh();
        }
    }
}
